package com.example.zg.ui_demo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.zg.ui_demo.beans.Dish;
import com.example.zg.ui_demo.beans.UserId;
import com.example.zg.ui_demo.recyclerview.RecyclerviewActivity;
import com.example.zg.ui_demo.retrofitservice.RetrofitService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {

    private EditText usernameView,passwordView;

    private Button longinButton;
    private Button registerButton;
    String userid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        registerButton=findViewById(R.id.button3);
        longinButton = findViewById(R.id.button);
        usernameView=findViewById(R.id.editText);
        passwordView=findViewById(R.id.editText3);

        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,RegiisterActivity.class);
                startActivity(intent);
                finish();
            }
        });

        longinButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,HomeActivity.class);
                intent.putExtra("user",usernameView.getText().toString());
               startActivity(intent);
               finish();
                //1
//                Retrofit retrofit=new Retrofit.Builder()
//                        .baseUrl("http://172.17.7.95:8080/MenuAPIDemo/")
//                        .addConverterFactory(GsonConverterFactory.create())
//                        .build();
//
//                //2
//                RetrofitService retrofitService=retrofit.create(RetrofitService.class);
//
//                //3
//                Call<List<Dish>> dishesCall=retrofitService.getDishes();
//
//                //4
//                dishesCall.enqueue(new Callback<List<Dish>>() {
//                    @Override
//                    public void onResponse(Call<List<Dish>> call, Response<List<Dish>> response) {
//                        List<Dish> dishes=response.body();
//                       Toast.makeText(MainActivity.this,"dish"+dishes.size(),Toast.LENGTH_SHORT).show();
////                        textView.setText(new Gson().toJson(dishes, new TypeToken<List<Dish>>(){}.getType()));
//
//                    }
//
//                    @Override
//                    public void onFailure(Call<List<Dish>> call, Throwable t) {
//                        Toast.makeText(MainActivity.this,"dish"+t.getMessage(),Toast.LENGTH_SHORT).show();
//                    }
//                });

      //          Retrofit retrofit=new Retrofit.Builder()
     //                   .baseUrl("http://172.24.10.175:8080/")
  //                      .addConverterFactory(GsonConverterFactory.create())
      //                  .build();
//
     //           RetrofitService retrofitService=retrofit.create(RetrofitService.class);

    //            Call<UserId> useridCall=retrofitService.getUserId("lnn","123456");

      //          useridCall.enqueue(new Callback<UserId>() {
       //             public void onResponse(Call<UserId> call, Response<UserId> response) {
      //                  UserId userId=response.body();
        //                System.out.println("sss:"+response.body().toString());
        //                Toast.makeText(MainActivity.this,"id+"+userId.getUserid().toString(),Toast.LENGTH_SHORT).show();
       //             }

         //           @Override
          //          public void onFailure(Call<UserId> call, Throwable t) {
          //              Toast.makeText(MainActivity.this,t.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
          //          }
         //       });
            }
        });
    }
}